﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.Skins;
using DevExpress.LookAndFeel;
using DevExpress.UserSkins;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraBars.Helpers;
using CNotebook;

namespace NotebookS2
{
    public partial class AddressBookList : RibbonForm
    {
        public AddressBookList()
        {
            InitializeComponent();
        }
        public string ConnectionString { get; set; }
        public bool IsCustomer { get; set; }
        public void PrintPreview()
        {
            if (!gridControl1.IsPrintingAvailable)
            {
                MessageBox.Show("The 'DevExpress.XtraPrinting' Library is not found", "Error");
                return;
            }
            // Opens the Preview window. 
            gridControl1.ShowPrintPreview();
        }
        void BindBP()
        {
            AddressBookManager oManager = new AddressBookManager();

            oManager.ConnectionString = this.ConnectionString;
            oManager.Open();

            DataTable table = oManager.GetAddressBook(IsCustomer);
            oManager.Close();

            gridControl1.DataSource = table;
            gridControl1.Refresh();

        }

        private void BusinessPartnerList_Load(object sender, EventArgs e)
        {
            BindBP();
        }

        private void txtBPCode_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            string sBPCode = ((DevExpress.XtraEditors.TextEdit)sender).Text;

            M_ADDRESSBOOK oForm = new M_ADDRESSBOOK();

            oForm.ConnectionString = this.ConnectionString;
            string sCustomer;

            if (IsCustomer == true)
            {
                sCustomer = "CUSTOMER";
            }
            else
            {
                sCustomer = "VENDOR";
            }
            oForm.OpenCustomer(sBPCode, sCustomer);
            oForm.MdiParent = this.MdiParent;
            oForm.Show();
        }
    }

}
